package com.info3k.client.commands.location;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.info3k.client.Info3K;
import com.info3k.client.components.LocationListWithSearch;
import com.info3k.client.domain.Category;

public class LocationCommand implements Command {
	
	private NewLocationCommand newLocationCommand;
	
	private Info3K info3k;
	
	private Category category;
	
	private Button addLocation = new Button(Info3K.msgs.new1() + " "+ Info3K.msgs.location(), new ClickHandler(){
		public void onClick(ClickEvent event) {
			newLocationCommand = new NewLocationCommand(info3k);
			newLocationCommand.execute();
		}
	});
	
	private RootPanel parent;
	
	private String searchTerm;
	
	public LocationCommand(RootPanel p, Info3K info, Category cat, String searchTerm){
		this.info3k = info;
		this.parent = p;
		this.category = cat;
		this.searchTerm = searchTerm;
	}
	
	public void execute() {
		parent.clear();
	
		final VerticalPanel verPanel = new VerticalPanel();
		
		if(info3k.getLoginManager().getUser()!=null) verPanel.add(addLocation);
		verPanel.setWidth("100%");
		parent.add(verPanel);
		
		LocationListWithSearch locationList = new LocationListWithSearch(false, info3k, category, searchTerm, "450px", null);
		locationList.setWidth("100%");
		verPanel.add(new HTML("<div class=\"h_line\"></div>"));
		
		verPanel.add(locationList);
	}
}
